package com.weipai.education.controller;

import com.weipai.education.model.CusRecord;
import com.weipai.education.model.Customer;
import com.weipai.education.model.UserCategory;
import com.weipai.education.model.api.Response;
import com.weipai.education.service.CustomerService;
import org.apache.ibatis.annotations.ResultMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @Author: 曹朋飞
 * @Date: 2018/12/10 17:22
 * 
 * 客户控制类
 */
@RestController
@Validated
public class CustomerController {
    
    @Autowired
    private CustomerService customerService;

    /**
     * 分页查询
     * @param page
     * @param size
     * @param key
     * @param type: 为null表示查询平台所有的客户，如果为own表示查询此经销商下面的客户
     * @return
     */
    @RequestMapping(value = "/customer/list", method = RequestMethod.GET)
    public Response list(@NotNull(message = "page不能为空") @RequestParam(value = "page") Integer page,
                         @NotNull(message = "size不能为空") @RequestParam(value = "size") Integer size,
                         @RequestParam(value = "key", required = false) String key,
                         @RequestParam(value = "type", required = false) String type){
        return customerService.list(page, size, key, type);
    }

    /**
     * 获取用户的详情
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/customer/getCustomerInfo", method = RequestMethod.GET)
    public Response getCustomerInfo(@NotBlank(message = "用户id不能为空") String customerId){
        return customerService.getCustomerInfo(customerId);
    }

    /**
     * 客户保存--修改
     * @param customer
     * @return
     */
    @RequestMapping(value = "/customer/save", method = RequestMethod.POST)
    public Response save(@Valid Customer customer, 
                         @RequestParam(value = "goodsBarCode", required = false) String goodsBarCode,
                         @RequestParam(value = "productId", required = false) String productId){
        return customerService.save(customer, goodsBarCode, productId);
    }

    /**
     * 更改客户的状态
     * @param id
     * @return
     */
    @RequestMapping(value = "/customer/changeStatus", method = RequestMethod.GET)
    public Response changeStatus(@NotBlank(message = "用户id不能为空") String id){
        return customerService.changeStatus(id);
    }

    /**
     * 添加与客户的沟通记录
     * @param cusRecord
     * @return
     */
    @RequestMapping(value = "/customer/saveCusRecord", method = RequestMethod.POST)
    public Response saveCusRecord(@Valid CusRecord cusRecord){
        return customerService.saveCusRecord(cusRecord);
    }

    /**
     * 查询与客户的沟通记录
     * @param customerId
     * @return
     */
    @RequestMapping(value = "/customer/getCusRecord", method = RequestMethod.GET)
    public Response getCusRecord(@NotBlank(message = "客户id不能为空") String customerId){
        return customerService.getCusRecord(customerId);
    }

    /**
     * 新增客户拿货
     * @param customerId
     * @param goodsBarCode
     * @return
     */
    @RequestMapping(value = "/customer/saveCusTakeGoods", method = RequestMethod.POST)
    public Response saveCusTakeGoods(@NotBlank(message = "客户id不能为空") String customerId,
                                     @NotBlank(message = "商品编号不能为空") String goodsBarCode,
                                     @NotBlank(message = "产品id不能为空") String productId){
        return customerService.saveCusTakeGoods(customerId, goodsBarCode, productId);
    }
}
